const { Sequelize, Op } = require('sequelize');
const { applyExtraSetup } = require('./extra-setup');
const config = require('../config');

// In a real app, you should keep the database connection URL as an environment variable.
// But for this example, we will just use a local SQLite database.
// const sequelize = new Sequelize(process.env.DB_CONNECTION_URL);
const sequelize = new Sequelize(config.database, config.username, config.password, {
  host: config.host,
  dialect: 'mssql',
  dialectOptions: {
    options: {
      enableArithAbort: false,
      validateBulkLoadParameters: false
    }
  },
  operatorsAliases: {
    $eq: Op.eq,
    $gt: Op.gt,
    $gte: Op.gte,
    $lt: Op.lt,
    $lte: Op.lte,
    $ne: Op.ne,
    $not: Op.not,
    $between: Op.between,
    $notBetween: Op.notBetween,
    $in: Op.in,
    $notIn: Op.notIn,
    $or: Op.or,
    $and: Op.and
  }
});

const modelDefiners = [
	require('../models/category.model'),
  require('../models/courseware_Content'),
  require('../models/siteserver_Channel'),
  
	// Add more models here...
	// require('./models/item'),
];

// We define all models according to their files.
for (const modelDefiner of modelDefiners) {
	modelDefiner(sequelize);
}

// We execute any extra setup after the models are defined, such as adding associations.
applyExtraSetup(sequelize);

// We export the sequelize connection instance to be used around our app.
module.exports = sequelize;